import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class Demo11CountDownLatch {

    /**
     * 倒数门栓，一个线程等待多个现成都执行完之后，再继续自己的工作。
     * @param args
     */

    public static void main(String[] args) {

        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 0; i < 6; i++) {
            new Thread(() -> {
                try {
                    TimeUnit.SECONDS.sleep(5);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName() + "\t上 完班，离开公司");
                countDownLatch.countDown();
            }, String.valueOf(i)).start();
        }
        new Thread(() -> {
            try {
                System.out.println(Thread.currentThread().getName() + "\t卷王最 后关灯走人");
                countDownLatch.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }, "7").start();


    }

}
